package com.offer;

/**
 * @Author: huangzhigao
 * @Date: 2023/3/4 18:54
 */
public class offer42 {
    public int maxSubArray(int[] nums) {
        int[] dp = new int[nums.length];
        dp[0] = nums[0];
        int res = Integer.MIN_VALUE;
        for (int i = 1; i < nums.length; i++) {
            dp[i] = Math.max(nums[i], dp[i - 1] + nums[i]);
            res = Math.max(res,dp[i]);
        }

        return Math.max(res,dp[0]);
    }
}
